﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;
using YJKRevitKernel.ElementSearchUtility.LinkDocumentSuite;
using YJKPatternSign.StairsRoomSection.DataDefine;
using YJKPatternSign.StairsRoomSection.Kit;

namespace YJKPatternSign.StairsRoomSection.ElementPacket
{
	internal class RoofObject : ComLayerObject
	{
		public RoofObject(BaseLinkDocumentResultBean LinkElem, SectionViewData secviewData = null) : base(LinkElem, secviewData)
		{
			this.m_objectType = ObjectType.kRoofType;
		}

		public override List<ElementObject> DividChild()
		{
			base.DividChild();
			foreach (ElementObject elementObject in base.LstChildObj)
			{
				elementObject.m_objectType = ObjectType.kRoofType;
				(elementObject as LayerObject).m_MaxLayerIndex = base.MaxLayerIndex;
				(elementObject as LayerObject).m_MinLayerIndex = base.MinLayerIndex;
				(elementObject as LayerObject).m_parentObj = this;
			}
			return base.LstChildObj;
		}

		public override Plane GetLastLayerCutPlane(int index, Line cutLine)
		{
			Element useElement = base.SelfElem.UseElement;
			double num = 0.0;
			bool flag = false;
			foreach (ElementObject elementObject in base.LstChildObj)
			{
				LayerObject layerObject = elementObject as LayerObject;
				if (layerObject.m_IndexPos == index)
				{
					num += layerObject.m_dWidth;
					flag = true;
					break;
				}
				num += layerObject.m_dWidth;
			}
			if (!flag)
			{
				return null;
			}
			XYZ xyz = new XYZ(0.0, 0.0, this.GetElevator());
			xyz -= num * XYZ.BasisZ;
			return RevitVersionFuncs.CreatePlanByNormalAndOrigin(XYZ.BasisZ, xyz);
		}

		private double GetElevator()
		{
			double result = 0.0;
			double num = 0.0;
			RoofBase roofBase = base.SelfElem.UseElement as RoofBase;
			Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_ATTR_THICKNESS_PARAM);
			if (parameter != null)
			{
				num = parameter.AsDouble();
			}
			Parameter parameter2 = roofBase.get_Parameter(BuiltInParameter.ROOF_BASE_LEVEL_PARAM);
			Document document = roofBase.Document;
			if (parameter2 != null)
			{
				ElementId elementId = parameter2.AsElementId();
				Element element = document.GetElement(elementId);
				if (element != null)
				{
					result = (element as Level).Elevation + num;
				}
				else
				{
					result = num;
				}
			}
			return result;
		}
	}
}
